package net.daum.hibernate;

import java.util.List;

import net.daum.hibernate.domain.Employee;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
public class Main {
	protected static Logger logger = LoggerFactory.getLogger(Main.class);
	
    @SuppressWarnings("unchecked")
    public static void main(String[] args) { 
        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session session = sf.openSession();
        session.beginTransaction();
 
//        Department department = new Department();
//        department.setDepartmentName("Sales");
//        session.save(department);
//         
//        Employee emp1 = new Employee("Nina", "Mayers", "111");
//        Employee emp2 = new Employee("Tony", "Almeida", "222");
// 
//        emp1.setDepartment(department);
//        emp2.setDepartment(department);
//         
//        session.save(emp1);
//        session.save(emp2);
//        
        Query query = session.createQuery("from Employee where employee_id < :employee_id");
        query.setParameter("employee_id", 10);
        List<Employee> list = query.list();
        System.out.println("-------------------------------" + list.size());
        for (Employee employee : list) {
			employee.getDepartment().getDepartmentName();
		}
//        
//        
//        
//        System.out.println(">>>" + session.get(Employee.class, new Long(22)));
//        
        //Department department2 = (Department) session.get(Department.class, new Long(115));
        //logger.debug("----------------------------------");
        //logger.debug(">>>" + department2.getEmployees());
 
        session.getTransaction().commit();
        session.close();
    }
}